package com.hz.email.controller;

import com.hz.email.entity.CommonResult;
import com.hz.email.entity.Payment;
import com.hz.email.service.PaymentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

@RestController
public class PaymentController {
    private Logger logger = LoggerFactory.getLogger(PaymentController.class);
    @Resource
    private PaymentService paymentService;
    @Value("${server.port}")
    private String serverPort;


    @PostMapping
    public CommonResult addPayment(@RequestBody Payment payment) {
        int a = paymentService.add(payment);
        logger.info("插入结果:" + a);
        if (a > 0) {
            return new CommonResult(a, "success=====》serverPort" + serverPort);
        } else {
            return new CommonResult(a, "error");
        }
    }

    @GetMapping(value = "/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id) {
        Payment payment = paymentService.getPaymentById(id);
        logger.info("查询结果为:" + payment);
        if (null == payment) {
            return new CommonResult<>(500, "error");
        } else {
            return new CommonResult<>(200, "success", payment);
        }
    }
}
